using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;

namespace eNets.CBK.Sockets;

sealed class SegmentList : ABufferList<ArraySegment<byte>>
{
}

abstract class ABufferList<T> : IList<T>
{
    private const int DEFAULT_CAPACITY = 16;
    
    private T[] _items;
    private int _size;
    
    public ABufferList()
    {
        _items = new T[DEFAULT_CAPACITY];
    }

    public T this[int index]
    {
        get { return _items[index]; }
        set { _items[index] = value; }
    }

    public int Count
    {
        get { return Volatile.Read(ref _size); }
    }

    public bool IsReadOnly => false;

    public void Add(T item)
    {
        var size = this.Count;
        if (size == _items.Length)
        {
            Array.Resize(ref _items, _items.Length * 2);
        }

        _items[size] = item;
        Volatile.Write(ref _size, size + 1);
    }

    public void Clear()
    {
        Volatile.Write(ref _size, 0);
    }

    public bool Contains(T item)
    {
        throw new NotImplementedException();
    }

    public void CopyTo(T[] array, int arrayIndex)
    {
        throw new NotImplementedException();
    }
    
    public int IndexOf(T item)
    {
        throw new NotImplementedException();
    }

    public void Insert(int index, T item)
    {
        throw new NotImplementedException();
    }

    public bool Remove(T item)
    {
        throw new NotImplementedException();
    }

    public void RemoveAt(int index)
    {
        throw new NotImplementedException();
    }

    public IEnumerator<T> GetEnumerator()
    {
        throw new NotImplementedException();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}